<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <title>我的成绩</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/all.min.css">
    <style>
        .container {
            padding: 20px;
        }
        .top-bar {
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .search-box {
            display: flex;
            align-items: center;
        }
        .search-box input, .search-box select {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-right: 10px;
            width: 200px;
        }
        .btn {
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            color: white;
        }
        .btn-primary {
            background-color: #1ab394;
        }
        .btn-primary:hover {
            background-color: #18a689;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e7eaec;
        }
        th {
            background-color: #f5f5f6;
            color: #333;
        }
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 20px;
        }
        .pagination button {
            margin: 0 5px;
            padding: 5px 10px;
            border: 1px solid #ddd;
            background-color: white;
            cursor: pointer;
            border-radius: 3px;
        }
        .pagination button:hover:not(:disabled) {
            background-color: #f5f5f5;
            color: #1ab394;
        }
        .pagination button.active {
            background-color: #1ab394;
            color: white;
            border-color: #1ab394;
        }
        .pagination button:disabled {
            background-color: #f5f5f5;
            cursor: not-allowed;
        }
        .pagination-info {
            margin: 0 15px;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="top-bar">
            <h2>我的成绩</h2>
            <div class="search-box">
                <select id="subjectSelect" onchange="search()">
                    <option value="">所有学科</option>
                    <c:forEach items="${subjectList}" var="subject">
                        <option value="${subject.subjectId}" ${param.subjectId == subject.subjectId ? 'selected' : ''}>
                            ${subject.subjectName}
                        </option>
                    </c:forEach>
                </select>
                <button class="btn btn-primary" onclick="search()">
                    <i class="fas fa-search"></i> 搜索
                </button>
            </div>
        </div>

        <table>
            <thead>
                <tr>
                    <th>学科名称</th>
                    <th>任课教师</th>
                    <th>成绩</th>
                    <th>录入时间</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${scoreList}" var="score">
                    <tr>
                        <td>${score.subjectName}</td>
                        <td>${score.teacherName}</td>
                        <td>${score.score}</td>
                        <td><fmt:formatDate value="${score.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>

        <div class="pagination">
            <button onclick="goToPage(${currentPage - 1})" ${currentPage <= 1 ? 'disabled' : ''}>
                <i class="fas fa-chevron-left"></i> 上一页
            </button>
            
            <c:forEach begin="1" end="${totalPages}" var="i">
                <c:choose>
                    <c:when test="${i == currentPage}">
                        <button class="active">${i}</button>
                    </c:when>
                    <c:otherwise>
                        <button onclick="goToPage(${i})">${i}</button>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            
            <button onclick="goToPage(${currentPage + 1})" ${currentPage >= totalPages ? 'disabled' : ''}>
                下一页 <i class="fas fa-chevron-right"></i>
            </button>
            
            <span class="pagination-info">
                共 ${totalCount} 条记录，${totalPages} 页
            </span>
        </div>
    </div>

    <script>
        function search() {
            const subjectId = document.getElementById('subjectSelect').value;
            const params = new URLSearchParams();
            if (subjectId) {
                params.append('subjectId', subjectId);
            }
            location.href = '${pageContext.request.contextPath}/admin/score/my?' + params.toString();
        }

        function goToPage(page) {
            const subjectId = document.getElementById('subjectSelect').value;
            const params = new URLSearchParams();
            params.append('page', page);
            if (subjectId) {
                params.append('subjectId', subjectId);
            }
            location.href = '${pageContext.request.contextPath}/admin/score/my?' + params.toString();
        }
    </script>
</body>
</html> 